package com.cmcc.linlaker.application;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.multidex.MultiDexApplication;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.bean.AreaListBean;
import com.cmcc.linlaker.bean.DepartmentListBean;
import com.cmcc.linlaker.bean.DictBean;
import com.cmcc.linlaker.utils.SPHelper;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import java.util.ArrayList;
import java.util.List;


public class LinhuApp extends MultiDexApplication {

    public static Context context;
    public static LinhuApp app;
    public static DisplayImageOptions options;

    public static List<DictBean.DictData> feedbackList = new ArrayList<>();
    public static List<DictBean.DictData> typeList = new ArrayList<>();
    public static List<DictBean.DictData> natureList = new ArrayList<>();
    public static List<DictBean.DictData> problemTypeList = new ArrayList<>();
    public static List<DictBean.DictData> problemSmallTypeList = new ArrayList<>();
    public static List<DictBean.DictData> formList = new ArrayList<>();
    public static List<DictBean.DictData> stateList = new ArrayList<>();
    public static List<DictBean.DictData> usingAttributesList = new ArrayList<>();
    public static List<DictBean.DictData> industryList = new ArrayList<>();
    public static List<DictBean.DictData> isList = new ArrayList<>();
    public static List<DictBean.DictData> processStatusList = new ArrayList<>();
//    public static List<DictBean.DictData> regionList = new ArrayList<>();
    public static List<AreaListBean.AreaListData> regionList = new ArrayList<>();
    public static List<DepartmentListBean.DepartmentData> departmentList = new ArrayList<>();
    /**
     * 获取上下文
     */
    public static Context getContext() {
        return context;
    }

    @Override
    public void onCreate() {
        super.onCreate();

        context = getApplicationContext();
        app = this;

        SPHelper.init(context);
//        Fresco.initialize(this);
        initImageLoader(getApplicationContext());

        BitmapFactory.Options decodingOptions = new BitmapFactory.Options();
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.image_default)
                .showImageForEmptyUri(R.mipmap.image_default)
                .showImageOnFail(R.mipmap.image_default)
                .decodingOptions(decodingOptions)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .considerExifParams(true)
                .imageScaleType(ImageScaleType.NONE)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .build();
    }

    public static void initImageLoader(Context context) {
        ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(context);
        config.threadPriority(Thread.NORM_PRIORITY - 2);
        config.denyCacheImageMultipleSizesInMemory();
        config.memoryCache(new WeakMemoryCache());
        config.diskCacheFileNameGenerator(new Md5FileNameGenerator());
        config.diskCacheSize(50 * 1024 * 1024); // 50 MiB
        config.tasksProcessingOrder(QueueProcessingType.LIFO);
        config.writeDebugLogs(); // Remove for release app

        ImageLoader.getInstance().init(config.build());
    }
}
